#include <stdio.h>
#include "public.h"
#include "exercises.h"

static int compare(const void *a, const void *b)
{
	return (*(int *)b - *(int *)a);
}
static void change_key(void *x, const void *key)
{
	*(int *)x = *(int *)key;
}

static void print(int *test, int num)
{
	int i;
	for (i = 0; i < num; i++) {
		printf("%d ", test[i]);
	}
	printf("\n");
}

int main(int argc, char *argv[])
{
	//int test[9] = {1, 3, 4, 2, 0, 6, 7, 8, 9};
	//int a = 5;
	//int *p = NULL;
	//print(test, 9);
	//printf("%d\n", _2_4(test, 9));
	//HEAP_SORT(test, 9, sizeof(int), compare);
	//print(test, 9);
	//p = BINARY_SEARCH(test, 10, sizeof(int), &a, compare);
	PQ *desc = NULL;
	PQ_element *e = NULL;
	int *t;
	int i;
	desc = create_PQ(10, compare, change_key);
	for (i = 0; i < 10; i++) {
		e = malloc_PQ(sizeof(int));
		t = ELEMENT_DATA(e);
		*t = i;
		insert_PQ(desc, e);
	}
	for (i = 0; i < 10; i++) {
		e = extract_PQ(desc);
		t = ELEMENT_DATA(e);
		printf("%d\n", *t);
		free_PQ(e);
	}
	return 0;
}
